﻿using Base.Api.Service;
using Common.AspNetCore;
using Common.Infrastructure;
using Common.RunModels.Base;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Base.Api.Controllers
{
    [Route("api/HRSync")]
    public class HRSyncController : ApiController
    {
        private readonly HRSyncService syncHRService;
        private readonly IConfiguration configuration;

        public HRSyncController(IServiceProvider provider, HRSyncService auth, IConfiguration config)
             : base(provider)
        {
            this.syncHRService = auth;
            this.configuration = config;
        }

        [HttpPost, Route("SyncDepart")]
        public async Task<ApiActionResult<HRSyncByDepartResultModel>> SyncDepart([FromBody] HRSyncByDepartParamModel model)
        {
            return await SafeExecuteAsync<HRSyncByDepartResultModel>(async (param) =>
            {
                return await this.syncHRService.SyncDepartAsync(model);
            });
        }

        [HttpPost, Route("SyncUser")]
        public async Task<ApiActionResult<HRSyncByUserResultModel>> SyncUser([FromBody] HRSyncByUserParamModel model)
        {
            return await SafeExecuteAsync<HRSyncByUserResultModel>(async (param) =>
            {
                return await this.syncHRService.SyncUsersAsync(model);
            });
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost, Route("GetDepartAttendUser")]
        public async Task<ApiActionResult<HRSyncByDepartAttendResultModel>> GetDepartAttendUser([FromBody] HRSyncByDepartAttendParamModel model)
        {
            return await SafeExecuteAsync<HRSyncByDepartAttendResultModel>(async (param) =>
            {
                return await this.syncHRService.GetDepartAttendUserAsync(model);
            });
        }

        /// <summary>
        /// 同步人员证书
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost, Route("SyncUserCer")]
        public async Task<ApiActionResult<HRSyncUserCerResultModel>> SyncUserCer([FromBody] HRSyncUserCerParamModel model)
        {
            return await SafeExecuteAsync<HRSyncUserCerResultModel>(async (param) =>
            {
                return await this.syncHRService.SyncUserCerAsync(model);
            });
        }
    }
}
